cc.Class({
    extends: cc.Component,

    properties: {

        lb_bar1: cc.Label,
        lb_bar2: cc.Label,
        lb_bar3: cc.Label,
        lb_bar4: cc.Label,
        lb_bar5: cc.Label,

    },

    onLoad () {
       var freeScroll = this.node.getComponent('FreeScroll');
        freeScroll.loadPage = (page, items, okCbk, noCbk) => this.loadPage(page, items, okCbk, noCbk);
        freeScroll.initItem = (node, data) => this.initItem(node, data);
        freeScroll.updateItem = (item, data) => this.updateItem(item, data);
        this.initWords();
    },

    initWords: function(){
        this.lb_bar1.string = LangLocal.word30;
        this.lb_bar2.string = LangLocal.word40;
        this.lb_bar3.string = LangLocal.word14;
        this.lb_bar4.string = LangLocal.word18;
        this.lb_bar5.string = LangLocal.word41;
    },
    start() {
        this.node.getComponent('FreeScroll').initView();
    },

    onItemClick(evt) {
        cc.Linker(URLS.PlayerHistoryDetail, {
            gameId: evt.detail.gameId
        }).request(data => {
            data.phase = evt.detail.phase;
            cc.Popup.show('DetailPop', pop => pop.init(data));
        });
    },

    loadPage(page, items, okCbk, noCbk) {
        cc.Linker(URLS.PlayerHistory, {
            page: page,
            pageSize: items
        }).autoLogin(true)
        .request(data => {
            if(page == 1 && !GLOBAL.IS_MOVE_END) {
                if(data[0].gameId == GLOBAL.gameState.gameId) data = data.slice(1);
            }
            okCbk && okCbk(data);
        }, noCbk);
    },

    initItem(node, data) {
        var item = node.getComponent('RecordItem');
        node.on('click', this.onItemClick, this);
        item.init(data);
        return item;
    },

    updateItem(item, data) {
        item.init(data);
    }
});
